#include "labellingpallet.hpp"

LabellingPallet::LabellingPallet(){
    Glib::RefPtr<Gnome::Glade::Xml> Widgetstree = Gnome::Glade::Xml::create("interface6.glade");

    Widgetstree->get_widget("window", window);
    Widgetstree->get_widget("spinbuttonsamplex", sample_x);
    Widgetstree->get_widget("spinbuttonsampley", sample_y);
    Widgetstree->get_widget("spinbuttonradius1", radius1);
    Widgetstree->get_widget("spinbuttonradius2", radius2);
    Widgetstree->get_widget("checkbuttonpasses", passes);
    Widgetstree->get_widget("checkbuttonpasses2", passes2);
    Widgetstree->get_widget("checkbuttoncolorize", colorizecheck);
    Widgetstree->get_widget("checkbuttoncolorize2", colorizecheck2);
    Widgetstree->get_widget("spinbuttoncriticaldistance", criticaldist);
    Widgetstree->get_widget("spinbuttonsuper1", superposition1);
    Widgetstree->get_widget("spinbuttonsuper2", superposition2);
    Widgetstree->get_widget("spinbuttonacute", acute);
    Widgetstree->get_widget("spinbuttonopposite", opposite);
    Widgetstree->get_widget("spinbuttonerosion", erosion);
    Widgetstree->get_widget("spinbuttonareafilter", areafilter);
    Widgetstree->get_widget("spinbuttonstability", stability);


    sample_x->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    sample_y->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    radius1->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    radius2->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    passes->signal_toggled().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    passes2->signal_toggled().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    colorizecheck->signal_toggled().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    colorizecheck2->signal_toggled().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    criticaldist->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    superposition2->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    superposition1->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    acute->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    opposite->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    areafilter->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));
    stability->signal_value_changed().connect(sigc::mem_fun(*this, &LabellingPallet::changeparams));



    samplesizex=30;
    samplesizey=45;
    radii1=30;
    radii2=29;
    showpasses=false;
    showpasses2=false;
    colorize=false;
    colorize2=false;

    erosionradius=4;
    areafiltervalue=150;

    window->show_all();
}


void LabellingPallet::changeparams(){
    samplesizex=sample_x->get_value_as_int();
    samplesizey=sample_y->get_value_as_int();
    radii1=radius1->get_value_as_int();

    erosionradius=erosion->get_value_as_int();
    areafiltervalue=areafilter->get_value_as_int();

    branchoptions.acute_threshold=(float)acute->get_value();
    branchoptions.critical_distance=criticaldist->get_value_as_int();
    branchoptions.opposite_threshold=(float)opposite->get_value();
    branchoptions.superposition_threshold_direct=(float)superposition1->get_value();
    branchoptions.superposition_threshold_opposite=(float)superposition2->get_value();
    branchoptions.stabilitycondition=stability->get_value_as_int();
}

Gtk::Window* LabellingPallet::getWindow(){
    return window;
}
